//
//  BaseModel.m
//  ToYourHeartNews
//
//  Created by XJing on 16/1/15.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel
//初始化  在初始化的时候就让字典给对象赋值了
-(instancetype)initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}
-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    //给没有找到key的不做任何操作
}
//便利构造器
+(instancetype)modelWithDic:(NSDictionary *)dic
{
    id m = [[[[self class] alloc]initWithDic:dic] autorelease];;
    return m;
}
//数组+字典->数组+对象
+(NSMutableArray *)modelHanderWithArray:(NSArray *)arr
{
    //1.创建空数组 保存处理后的model对象
    NSMutableArray *mArr = [NSMutableArray array];
    //2.遍历传入的数组参数 得到每个字典信息
    for (NSDictionary *dic in arr) {
        id m = [[self class] modelWithDic:dic];
        [mArr addObject:m];
    }
    return mArr;
}

@end
